home *** CD-ROM | disk | FTP | other *** search
- unit UMouseDemo;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, ComCtrls, ExtCtrls;
-
- type
- TForm1 = class(TForm)
- Panel1: TPanel;
- procedure FormCreate(Sender: TObject);
- private
- { Private declarations }
- fIntelliWheelSupport: Boolean; // True if IntelliMouse + wheel enabled
- fIntelliMessage: UINT; // message sent from mouse on wheel roll
- fIntelliScrollLines: Integer; // number of lines to scroll per wheel roll
- procedure IntelliMouseInit;
- procedure WndProc (var Message: TMessage); override;
- procedure WMMouseWheel (var Message: TMessage); message wm_MouseWheel;
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- IntelliMouseInit;
- end;
-
- procedure TForm1.WndProc (var Message: TMessage);
-
- function GetShiftState: Integer;
- begin
- Result := 0;
- if GetAsyncKeyState (vk_Shift) < 0 then Result := Result or mk_Shift;
- if GetAsyncKeyState (vk_Control) < 0 then Result := Result or mk_Control;
- if GetAsyncKeyState (vk_LButton) < 0 then Result := Result or mk_LButton;
- if GetAsyncKeyState (vk_RButton) < 0 then Result := Result or mk_RButton;
- if GetAsyncKeyState (vk_MButton) < 0 then Result := Result or mk_MButton;
- end;
-
- begin
- { If the message is non-native, eat the non-native message and post a native }
- { message. We don't call Inherited, thus ensuring original message is discarded. }
- if (Message.Msg = fIntelliMessage) and (fIntelliMessage <> wm_MouseWheel) then begin
- { We need to convert the non-native info into native format. Bleugh! }
- PostMessage (Handle, wm_MouseWheel, MakeLong (GetShiftState, Message.wParam), Message.lParam);
- end else Inherited;
- end;
-
- procedure TForm1.WMMouseWheel (var Message: TMessage);
- const
- Delta: SmallInt = 0;
- var
- Idx: Integer;
- begin
- Delta := Delta + HiWord (Message.wParam);
- while Abs(Delta) >= 120 do begin
- if Delta < 0 then begin
- for Idx := 0 to fIntelliScrollLines - 1 do
- PostMessage (Handle, wm_VScroll, MakeLong (sb_LineDown, 0), 0);
- Delta := Delta + 120;
- end else begin
- for Idx := 0 to fIntelliScrollLines - 1 do
- PostMessage (Handle, wm_VScroll, MakeLong (sb_LineUp, 0), 0);
- Delta := Delta - 120;
- end;
- end;
- end;
-
- procedure TForm1.IntelliMouseInit;
- var
- hWndMouse: hWnd;
- mQueryScrollLines: UINT;
-
- function NativeMouseWheelSupport: Boolean;
- var
- ver: TOSVersionInfo;
- begin
- Result := False;
- ver.dwOSVersionInfoSize := sizeof (ver);
- // For Windows 98, assume dwMajorVersion = 5 (It's 4 for W95)
- // For NT, we need 4.0 or better.
- if GetVersionEx (ver) then case ver.dwPlatformID of
- ver_Platform_Win32_Windows: Result := ver.dwMajorVersion >= 5;
- ver_Platform_Win32_NT: Result := ver.dwMajorVersion >= 4;
- end;
-
- { Quick and dirty temporary hack for Windows 98 beta 3 }
- if (Result = False) and (ver.szCSDVersion = ' Beta 3') then Result := True;
- end;
-
- begin
- if NativeMouseWheelSupport then begin
- fIntelliWheelSupport := Boolean (GetSystemMetrics (sm_MouseWheelPresent));
- SystemParametersInfo (spi_GetWheelScrollLines, 0, @fIntelliScrollLines, 0);
- fIntelliMessage := wm_MouseWheel;
- end else begin
- { Look for hidden mouse window }
- hWndMouse := FindWindow ('MouseZ', 'Magellan MSWHEEL');
- if hWndMouse <> 0 then begin
- { We're in business - get the scroll line info }
- fIntelliWheelSupport := True;
- mQueryScrollLines := RegisterWindowMessage ('MSH_SCROLL_LINES_MSG');
- fIntelliScrollLines := SendMessage (hWndMouse, mQueryScrollLines, 0, 0);
- { Finally, get the custom mouse message as well }
- fIntelliMessage := RegisterWindowMessage ('MSWHEEL_ROLLMSG');
- end;
- end;
-
- if (fIntelliScrollLines < 0) or (fIntelliScrollLines > 100) then fIntelliScrollLines := 3;
- end;
-
- end.
-
-